home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
foss11b3.zip
/
DEVELOP
/
UTILCOLL
/
TOPTEN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-10-24
|
14KB
|
421 lines
program TopTen;
uses
TParam,
TFileIO,
TOSInt,
ApiInt,
Bits,
Types;
label
NextTopUser,
NextDown,
NextUp,
NextFDown,
NextFUp;
type
PTopTenBull = ^TTopTenBull;
TTopTenBull = object
Language : Char;
SkipFile : string;
AreaCode : string;
BullPath : string;
constructor Init;
destructor Done;
procedure ReadParams;
procedure CreateBull;
end;
var
TopTenBull : PTopTenBull;
constructor TTopTenBull.Init;
begin
dllInit( '', 0 );
end; { contructor Init }
destructor TTopTenBull.Done;
begin
end; { destructor Done }
procedure TTopTenBull.ReadParams;
begin
if Par^.SwAct['L'] then
case UpCh( Par^.SwStr['L', 1] ) of
'A': Language := 'A';
'E': Language := 'E';
'N': Language := 'N';
else
Language := 'A';
end
else Language := 'A';
SkipFile := '';
if Par^.SwAct['S'] then
if FileExist( Par^.SwStr['S'] ) then
SkipFile := Par^.SwStr['S'];
if Par^.SwAct['A'] then AreaCode := Par^.SwStr['A']
else AreaCode := 'MAIN';
BullPath := Par^.Str[1];
end; { procedure ReadParams }
procedure TTopTenBull.CreateBull;
type
PTopTenData = ^TTopTenData;
TTopTenData = record
TotalTime,
TotalOn,
TotalDown,
TotalUp,
TotalFiles : LongInt;
TotalMDown,
TotalMUp,
TotalMB : Real;
TopUserTime,
TopUserCnt,
Down,
Up : array[1..10] of LocUsers;
FDown,
FUp : array[1..10] of TFileRec;
end;
const
TopLine = '┌────────────────────────────────────┐ ┌────────────────────────────────────┐';
BottomLine = '└────────────────────────────────────┘ └────────────────────────────────────┘'#13#10 +
'
'#13#10'%!m%';
var
T10 : PTopTenData;
User : LocUsers;
FPos : LongInt;
L1, L2 : LongInt;
Area : Area_Config_Record;
Dir : TFileRec;
OutE,
OutN : TFile;
Year : Word;
Month, Day : Byte;
TmpStr : string;
TmpTime : LongInt;
{}function SkipUser( Name : string ) : Boolean;
var
SkFile : TFile;
NameMask : string;
begin
if not ( Length( SkipFile ) = 0 ) then
with SkFile do
begin
Assign( SkipFile,
fmReadOnly or fmDenyWrite,
1,
faNormalAccess,
ftMaxTimeout );
Reset;
while not Eof do
begin
ReadTextln( NameMask );
if LookInIf( Name, NameMask ) then
begin
Close;
SkipUser := TRUE;
exit;
end;
end;
Close;
end;
SkipUser := FALSE;
{}end;
{}procedure PrintOut ( Lang : Char; Txt : String );
begin
if ( Lang in ['A', 'E'] ) then OutE.WriteTextln( Txt );
if ( Lang in ['A', 'N'] ) then OutN.WriteTextln( Txt );
{}end; { Procedure PrintOut }
begin
New( T10 );
FillChar( T10^, SizeOf( T10^ ), 0 );
Write( ' - Scanning user: ' );
FPos := 0;
while fioReadLocalUsr( User, FPos ) do
begin
OS^.Sleep( 2 );
Inc( FPos );
if ( Killed in User.Flags ) then Continue;
Write( Fill( User.UserName, High( User.UserName ), ' ' ) +
Fill( '', High( User.UserName ), #8 ));
with T10^ do
begin
Inc( TotalTime, User.TimeTotal );
Inc( TotalOn, User.TimesOn );
Inc( TotalDown, User.Downloads );
TotalMDown := TotalMDown + User.DownloadKB / 1024;
Inc( TotalUp, User.Uploads );
TotalMUp := TotalMUp + User.UploadKB / 1024;
if not SkipUser( User.UserName ) then
begin
for L1 := 1 to 10 do
if ( TopUserTime[L1].TimeTotal < User.TimeTotal ) then
begin
for L2 := 9 downto L1 do
TopUserTime[L2 + 1] := TopUserTime[L2];
TopUserTime[L1] := User;
Break;
end;
for L1 := 1 to 10 do
if ( TopUserCnt[L1].TimesOn < User.TimesOn ) then
begin
for L2 := 9 downto L1 do
TopUserCnt[L2 + 1] := TopUserCnt[L2];
TopUserCnt[L1] := User;
Break;
end;
for L1 := 1 to 10 do
if ( Down[L1].Downloads < User.Downloads ) then
begin
for L2 := 9 downto L1 do
Down[L2 + 1] := Down[L2];
Down[L1] := User;
Break;
end;
for L1 := 1 to 10 do
if ( Up[L1].Uploads < User.Uploads) then
begin
for L2 := 9 downto L1 do
Up[L2 + 1] := Up[L2];
Up[L1] := User;
Break;
end;
end { if SkipUser( User ) }
else
begin
Writeln( Fill( '', 19, #8 ) +
' - Skipped user: ' + User.UserName + '. ' );
Write( ' - Scanning user: ' );
end; { if SkipUser( User ) else }
end;
end;
Write( Fill( '', High( User.UserName ), ' ') +
Fill( '', 19 + High( User.UserName ), #8 ));
fioFindAreaCode( Area, AreaCode, 0 );
Write( ' - Scanning file: ' );
FPos := 0;
while fioReadFileRec( Dir, Area, FPos ) do
begin
OS^.Sleep( 2 );
Inc( FPos );
if ( KilledFile in Dir.FileFlags ) then Continue;
Write( Fill( Dir.FileName, High( Dir.FileName ), ' ' ) +
Fill( '', High( Dir.FileName ), #8 ));
with T10^ do
begin
Inc( TotalFiles );
TotalMB := TotalMB + Dir.Size / 1048576;
for L1 := 1 to 10 do
if (FDown[L1].Downloads<Dir.Downloads) then
begin
for L2 := 9 downto L1 do
FDown[L2+1] := FDown[L2];
FDown[L1] := Dir;
Break;
end;
end;
end;
Write( Fill( '', High( User.UserName ), ' ') +
Fill( '', 19 + High( User.UserName ), #8 ));
if ( Language in ['A', 'E'] ) then
begin
with OutE do
begin
Assign( BullPath + '.E',
fmWriteOnly or fmExclusive,
1,
faNormalAccess,
ftMaxTimeout );
ReWrite;
end;
end;
if ( Language in ['A', 'N'] ) then
begin
with OutN do
begin
Assign( BullPath + '.N',
fmWriteOnly or fmExclusive,
1,
faNormalAccess,
ftMaxTimeout );
ReWrite;
end;
end;
with T10^ do
begin
Date( Year, Month, Day );
TmpTime := TimeNow;
PrintOut( 'E', '
' + Fill( ' TopTen statistics', 39, ' ' ) +
PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
PrintOut( 'N', '
' + Fill( ' Ti på topp statistikk', 39, ' ' ) +
PreFill( TimeStr( TmpTime ) + ' ' + DateStr( Year, Month, Day ), 38, ' ' ) + ' ' );
PrintOut( 'A', '' );
PrintOut( 'E', '
' + Center( 'TOP-10 USERS', 78, ' ' ));
PrintOut( 'N', '
' + Center( 'TI PÅ TOPP BRUKERE', 78, ' ' ));
PrintOut( 'A', '
' );
PrintOut( 'E', Center( 'Total user time: ' + I2S( TotalTime, 0 ), 78, ' ' ));
PrintOut( 'N', Center( 'Total bruker tid: ' + I2S( TotalTime, 0 ) ,78, ' ' ));
PrintOut( 'E', Center( 'Total number of logons: ' + I2S( TotalOn, 0 ), 78, ' ' ));
PrintOut( 'N', Center( 'Antall pålogginger: ' + I2S( TotalOn, 0 ), 78, ' ' ));
PrintOut( 'A', '' );
PrintOut( 'E', '
Username Minutes Username Logons
' );
PrintOut( 'N', '
Brukernavn Minutter Pålogginger Pålogginger
' );
PrintOut( 'A', TopLine );
for L1 := 1 to 10 do
begin
if ( L1 = 1 ) then TmpStr := '
'
else TmpStr := '
';
PrintOut( 'A',